package com.xdwanj.service.impl;

import com.xdwanj.dao.OrderDao;
import com.xdwanj.dao.impl.OrderDaoImpl;
import com.xdwanj.pojo.Order;
import com.xdwanj.service.OrderService;
import com.xdwanj.util.PageBean;

public class OrderServiceImpl implements OrderService {
    OrderDao orderDao = new OrderDaoImpl();

    @Override
    public PageBean<Order> findOrderListByUid(int id, int pageSize, int currentPageNo) {
        PageBean<Order> customerPageDto = null;
        try {
            customerPageDto = orderDao.findOrderListByUid(id, pageSize, currentPageNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return customerPageDto;
    }

    @Override
    public boolean deleteOrderByOid(int oid) {
        int deleteRow = 0;

        try {
            deleteRow = orderDao.deleteOrder(oid);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return deleteRow == 2;
    }


    @Override
    public boolean finish(int id, int state) {
        try {
            orderDao.updateOrderStatus(id, state);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public boolean addOrder(Order order, int uid, int coid) {
        boolean flag = false;

        try {
            orderDao.insertOrder(order, uid, coid);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return flag;
    }

    @Override
    public boolean updateOrder(Order order, int uid, int coid) {
        boolean flag = false;

        try {
            orderDao.updateOrder(order, uid, coid);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return flag;
    }

    @Override
    public PageBean<Order> findOrderList(int currentPageNo, int PageSize) {
        PageBean<Order> orderList = null;

        try {
            orderList = orderDao.findOrderList(currentPageNo, PageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return orderList;
    }

    @Override
    public Order findOrderById(int oid) {
        Order order = null;

        try {
            order = orderDao.findOrderById(oid);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return order;
    }
}
